#include "stdafx.h"
#include "utils.h"
#include "MenuInfo.h"
#include <winuser.h>
using namespace std;

static UINT CURRENT_MENU_NUMBER = 8;

const vector<CMenuInfo*> CMenuInfo::NoSubMenus = vector<CMenuInfo*>();

CMenuInfo g_AllMenus[20];
extern HINSTANCE g_hInstance;

HRESULT InitializeAllMenuItems()
{

	HRESULT hr = E_OUTOFMEMORY;
	for (UINT i = 0;i<GetAllMenusNumber();i++)
	{
		g_AllMenus[i].menuID = i;
		g_AllMenus[i].subMenus.clear();
	}
	if(g_AllMenus)
	{
		hr = S_OK;
	}


	HANDLE hbitmap = LoadImage(g_hInstance, MAKEINTRESOURCE(IDB_MARK), 
		IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT);

	//TODO:Memory leaks happens.

	//TODO:Scripting Menu Initialization will be better.
	__DebugFunctionCall("InitializeAllMenu");
	//@Commit:Normal Case No ICon
	g_AllMenus[0].name = L"Normal Case";
	g_AllMenus[0].cmdString =L"Normal Case Demo Descriptor.";
	g_AllMenus[0].hBitmapICon = NULL;/*No Icon*/
	g_AllMenus[0].OnCommand = 	[](void * pParam) ->void{ MessageBox(NULL,L"Normal Case Window",L"Demo",0);};
	g_AllMenus[0].isPopup = false;
	g_AllMenus[0].subMenus = CMenuInfo::NoSubMenus;
	g_AllMenus[0].hasParent = false;
	//@Commit:Normal Case With ICon
	g_AllMenus[1].name = L"ICon Case";
	g_AllMenus[1].cmdString =L"ICon Case Demo Descriptor.";
	g_AllMenus[1].hBitmapICon = hbitmap;/*With Icon*/
	g_AllMenus[1].OnCommand = 	[](void * pParam) ->void{ MessageBox(NULL,L"Normal Case ICon Window",L"Demo",0);};
	g_AllMenus[1].isPopup = false;
	g_AllMenus[1].subMenus = CMenuInfo::NoSubMenus;
	g_AllMenus[1].hasParent = false;
	
	//@Commit:Popup Menu
	g_AllMenus[2].name = L"Popup Case";
	g_AllMenus[2].cmdString = L"Popup Case Demo Descriptor.";
	g_AllMenus[2].hBitmapICon = hbitmap;
	g_AllMenus[2].OnCommand = [](void*)->void {__DebugLog("Never Call This.");};
	g_AllMenus[2].isPopup = true;
	/*It's Sub*/
	g_AllMenus[2].subMenus.push_back(&g_AllMenus[3]);
	g_AllMenus[2].subMenus.push_back(&g_AllMenus[4]);
	g_AllMenus[2].subMenus.push_back(&g_AllMenus[5]);
	g_AllMenus[2].hasParent = false;
	
	g_AllMenus[3].name = L"SubMenu 1";
	g_AllMenus[3].cmdString = L"SubMenu 1 Case Demo Descriptor.";
	g_AllMenus[3].hBitmapICon = NULL;
	g_AllMenus[3].OnCommand = [](void * pParam) ->void{ MessageBox(NULL,L"SubMenu 1 Window",L"Demo",0);};
	g_AllMenus[3].isPopup = false;
	g_AllMenus[3].subMenus = CMenuInfo::NoSubMenus;
	g_AllMenus[3].hasParent = true;

	g_AllMenus[4].name = L"SubMenu 2";
	g_AllMenus[4].cmdString = L"SubMenu 2 Case Demo Descriptor.";
	g_AllMenus[4].hBitmapICon = hbitmap;
	g_AllMenus[4].OnCommand = [](void * pParam) ->void{ MessageBox(NULL,L"SubMenu 2 Window",L"Demo",0);};
	g_AllMenus[4].isPopup = false;
	g_AllMenus[4].subMenus = CMenuInfo::NoSubMenus;
	g_AllMenus[4].hasParent = true;

	g_AllMenus[5].name = L"SubMenu 3";
	g_AllMenus[5].cmdString = L"SubMenu 3 Case Demo Descriptor.";
	g_AllMenus[5].hBitmapICon = NULL;
	g_AllMenus[5].OnCommand = [](void * pParam) ->void{ MessageBox(NULL,L"SubMenu 3 Window",L"Demo",0);};
	g_AllMenus[5].isPopup = true;
	g_AllMenus[5].subMenus.push_back(&g_AllMenus[6]);
	g_AllMenus[5].subMenus.push_back(&g_AllMenus[7]);
	g_AllMenus[5].hasParent = true;

	g_AllMenus[6].name = L"SubMenu 4";
	g_AllMenus[6].cmdString = L"SubMenu 4 Case Demo Descriptor.";
	g_AllMenus[6].hBitmapICon = NULL;
	g_AllMenus[6].OnCommand = [](void * pParam) ->void{ MessageBox(NULL,L"SubMenu 4 Window",L"Demo",0);};
	g_AllMenus[6].isPopup = false;
	g_AllMenus[6].subMenus = CMenuInfo::NoSubMenus;
	g_AllMenus[6].hasParent = true;

	g_AllMenus[7].name = L"SubMenu 5";
	g_AllMenus[7].cmdString = L"SubMenu 5 Case Demo Descriptor.";
	g_AllMenus[7].hBitmapICon = NULL;
	g_AllMenus[7].OnCommand = [](void * pParam) ->void{ MessageBox(NULL,L"SubMenu 5 Window",L"Demo",0);};
	g_AllMenus[7].isPopup = false;
	g_AllMenus[7].subMenus = CMenuInfo::NoSubMenus;
	g_AllMenus[7].hasParent = true;
	return hr;
}


//@Commit:Release system resource while dll deregister.
HRESULT ReleaseMenuResource()
{
	//TODO:Release All Resource that accquied while initializing.
	return S_OK;
}

UINT GetAllMenusNumber()
{
	return CURRENT_MENU_NUMBER;
}

CMenuInfo* GetAllMenuInstatnce()
{
	return g_AllMenus;
}
